<?php

use yii\helpers\Html;
use eric\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model app\models\User */
/* @var $form \eric\widgets\ActiveForm */
?>

<div class="user-form">

    <?php $form = ActiveForm::begin([
        'enableAjaxSubmit' => true,
        'ajaxSubmitSuccess' => "function(data){\$('#user_modal').modal('hide');\$.pjax.reload('#user_grid_pjax');}",
        'type' => ActiveForm::TYPE_HORIZONTAL,
        'options' => [
            'id' => 'user_form',
            'class' => 'form-horizontal form-bordered',
        ]
    ]);
    ?>

    <?= $form->field($model, 'username')->textInput(['maxlength' => 32]);?>
    <?php
    $jcropdone = <<<JS
    function(e, api, data){
        api.setImage(data);
        var id=$(e.currentTarget).attr("id");
        var container = $('#'+id+'_container');
        var hiddenInput = container.next('input[type=hidden]');
        hiddenInput.val(data);
    }
JS;
    ?>
    <?= $form->field($model, 'headpic')->widget(\eric\widgets\jcrop\NewJcrop::className(),[
        'enableFileUpload' => true,
        'mainLayout' => '{jcrop}{fileuploader}',
        'jcropLayout' => '<div class="pull-left">{image}</div><div class="pull-left">{toolbar}</div>',
        'clientEvents' => [
            'jcropdone' => $jcropdone
        ],
        'ratioButtons' => [
            [
                'width' => 300,
                'height' => 300,
                'type' => 'size',
            ]
        ],
        'clientOptions' => [
            'boxWidth' => 300,
            'boxHeight' => 300,
        ]
    ] ) ; ?>

    <?= $form->field($model, 'infopic')->widget(\eric\widgets\FileUpload::className(), []) ?>

    <?php if(!isset($model->password)):?>
    <?= $form->field($model, 'password')->passwordInput(['maxlength' => 16]) ?>
    <?php endif;?>
    <?= $form->field($model, 'name')->textInput(['maxlength' => 32]) ?>

    <?= $form->field($model, 'age')->textInput() ?>

    <?php if(!isset($model->gender))$model->gender = 1;?>
    <?= $form->field($model, 'gender')->radioList([1 => 'male', 0 => 'female']) ?>

    <?=  $form->field($model, 'certno')->textInput()?>

    <?=  $form->field($model, 'desc')->widget(\eric\widgets\editor\Editor::className(), [])?>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-support1' : 'btn btn-support3']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>